package com.travel.carmen;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;


/**
	Quick Notes for the Travel Mobile Application Carmen.
	 The View is the Quick Note List View (layout as per quicknotes.xml) for the application.
	 Provides users with quick access to notes lying on the device. These notes do not
	 require a registered user nor any XMLRPC requests to Carmen (Drupal) Website.
   	@author Arturo Aparicio 
   	@author Edwin Boykin 
   	@author Veena Chengalnaidu
   	@author Anton Ganeshalingam
   	@author Lakshmi Mallampati
   	@author Tarun Morton
   	@author Chantha Thoeun
*/
public class QuickNotes extends Activity implements OnItemClickListener 
{
	private ListView notes;
	private String result = "";
	
	
	@Override
	/**
	   Called when the activity is first created.
	    The UI activities as per quicknotes.xml are inflated.
	    All listeners and adapters are attached and all settings are
	    made to default.
	 */
	public void onCreate(Bundle bundle)
	{
		super.onCreate(bundle);
		setContentView(R.layout.quicknotes);
		notes = (ListView) findViewById(R.id.list_of_notes);
		//Used to populate notes
		ArrayAdapter default_notes = ArrayAdapter.createFromResource(this, 
				R.array.default_notes, android.R.layout.simple_list_item_1);
		notes.setAdapter(default_notes);
		notes.setOnItemClickListener(this);
	}
	
	
	/**
	   ListView Listener to return the Note and control back to the Main
	    interface of Carmen Travel Mobile Application
	   @param arg0 AdapterView for this listener
	   @param arg1 View for this listener
	   @param arg2 position of Quick Note selected
	   @param arg3 --
	 */
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		result = notes.getAdapter().getItem(arg2).toString();
		Intent resultIntent = new Intent();
		resultIntent.putExtra(getString(R.string.query_quick_note), result);
		setResult(Activity.RESULT_OK, resultIntent);
		finish();
	}
}
